package cn.piesat.vo;

import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * 
 * @author: demo
 * @date: 2020年7月2日
 * @Document :请求记录
 */
public class RecordVo {
	public RecordVo(){
		super();
	}

	public RecordVo(String id, String clientAddress, String requestAddress, String gatewayAddress, String url, String method, String requestHeader, String requestParam, String responseBody, Date startTime, Date endTime, Integer status, Long spendTime, Integer type, String userName, String operation, String locatoion) {
		this.id = id;
		this.clientAddress = clientAddress;
		this.requestAddress = requestAddress;
		this.gatewayAddress = gatewayAddress;
		this.url = url;
		this.method = method;
		this.requestHeader = requestHeader;
		this.requestParam = requestParam;
		this.responseBody = responseBody;
		this.startTime = startTime;
		this.endTime = endTime;
		this.status = status;
		this.spendTime = spendTime;
		this.type = type;
		this.userName = userName;
		this.operation = operation;
		this.locatoion = locatoion;
	}

	public RecordVo(String  id) {
		this.id=id;
	}

	/**
	 * 日志信息记录表主键id
	 */
	private String id;
	
	/**
	 * 请求客户地址
	 */
	private  String  clientAddress;
	/**
	 * 请求地址
	 */
	
	private  String  requestAddress;
	
	/**
	 * gateway代理真实地址
	 */
	private  String  gatewayAddress;
	
	/**
	 * 请求url
	 */
	private  String  url;
	
	/**
	 * 请求方法
	 */
	private  String  method;
	/**
	 * 请求头
	 */
	private  String  requestHeader;
	/**
	 * 请求参数记录
	 */
	private String requestParam;

	/**
	 * 返回结果记录
	 */
	private String responseBody;
	/**
	 * 操作时间
	 */
	private Date startTime;
	/**
	 * 响应时间
	 */
	private Date endTime;

	/**
	 * 响应结果1成功0失败
	 */
	private Integer status;
	
	/**
	 * 时间差
	 */
	private Long  spendTime;
	private Integer type;
	private String userName;
	private String operation;
	private String locatoion;
	private String roles;
	/**
	 * 拼接响应体
	 * @param response
	 */
	public void appendResponseBody(String response) {

		if (StringUtils.isNotBlank(this.responseBody)) {
			this.responseBody = this.responseBody.concat(response);
		} else {
			this.responseBody = response;
		}
	}
	/**
	 * 计算时间差
	 */
	public  void  calcSpendTime() {
		if (this.endTime==null || this.startTime==null) {
			return ;
		}
		long time=  this.endTime.getTime()-this.startTime.getTime();
		this.setSpendTime(time);
	}

	public String getLocatoion() {
		return locatoion;
	}

	public void setLocatoion(String locatoion) {
		this.locatoion = locatoion;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getOperation() {
		return operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getClientAddress() {
		return clientAddress;
	}

	public void setClientAddress(String clientAddress) {
		this.clientAddress = clientAddress;
	}

	public String getRequestAddress() {
		return requestAddress;
	}

	public void setRequestAddress(String requestAddress) {
		this.requestAddress = requestAddress;
	}

	public String getGatewayAddress() {
		return gatewayAddress;
	}

	public void setGatewayAddress(String gatewayAddress) {
		this.gatewayAddress = gatewayAddress;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getRequestHeader() {
		return requestHeader;
	}

	public void setRequestHeader(String requestHeader) {
		this.requestHeader = requestHeader;
	}

	public String getRequestParam() {
		return requestParam;
	}

	public void setRequestParam(String requestParam) {
		this.requestParam = requestParam;
	}

	public String getResponseBody() {
		return responseBody;
	}

	public void setResponseBody(String responseBody) {
		this.responseBody = responseBody;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Long getSpendTime() {
		return spendTime;
	}

	public void setSpendTime(Long spendTime) {
		this.spendTime = spendTime;
	}

	public String getRoles() {
		return roles;
	}

	public void setRoles(String roles) {
		this.roles = roles;
	}

	@Override
	public String toString() {
		return "RecordVo{" +
				"id='" + id + '\'' +
				", clientAddress='" + clientAddress + '\'' +
				", requestAddress='" + requestAddress + '\'' +
				", gatewayAddress='" + gatewayAddress + '\'' +
				", url='" + url + '\'' +
				", method='" + method + '\'' +
				", requestHeader='" + requestHeader + '\'' +
				", requestParam='" + requestParam + '\'' +
				", responseBody='" + responseBody + '\'' +
				", startTime=" + startTime +
				", endTime=" + endTime +
				", status=" + status +
				", spendTime=" + spendTime +
				", type=" + type +
				", userName='" + userName + '\'' +
				", operation='" + operation + '\'' +
				", locatoion='" + locatoion + '\'' +
				", roles='" + roles + '\'' +
				'}';
	}
}
